package com.yanqu.road.server.logic.activity.condition.twins;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.twins.TwinsUserKungFuData;
import com.yanqu.road.entity.activity.twins.config.TwinsKungFuConfig;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.activity.BaseActivityData;
import com.yanqu.road.server.logic.activity.condition.BaseActivityCondition;
import com.yanqu.road.server.manger.activity.twins.TwinsMgr;

import java.math.BigInteger;
import java.util.List;
import java.util.Map;

public class TwinsKungFuCombCondition extends BaseActivityCondition {

    public TwinsKungFuCombCondition(ActivityInfo activityInfo, ActivityConditionInfo activityConditionInfo, BaseActivityData baseActivityData) {
        super(activityInfo, activityConditionInfo, baseActivityData);
    }

    @Override
    protected void player_BoardLevelHandle(Object object) {
        Map<Integer, TwinsUserKungFuData> unlockMap = (Map<Integer, TwinsUserKungFuData>) object;
        List<BigInteger> paramList = getActivityConditionInfo().getParamList();
        int wuxueType = paramList.get(1).intValue();
        int menpaiType = paramList.get(2).intValue();
        int levelCount = paramList.get(3).intValue();
        int lvevl = 0;
        if(wuxueType > 0){
            for(TwinsUserKungFuData kungFuData : unlockMap.values()){
                TwinsKungFuConfig kfConfig = TwinsMgr.getConfig().getKungFuConfig(kungFuData.getKungFuId(),kungFuData.getLevel());
                if(kfConfig != null && kfConfig.getKungfuType() == wuxueType){
                    lvevl = lvevl + kungFuData.getLevel();
                }
            }
        }
        if(menpaiType > 0){
            for(TwinsUserKungFuData kungFuData : unlockMap.values()){
                TwinsKungFuConfig kfConfig = TwinsMgr.getConfig().getKungFuConfig(kungFuData.getKungFuId(),kungFuData.getLevel());
                if(kfConfig != null && kfConfig.getOriginType() == menpaiType){
                    lvevl = lvevl + kungFuData.getLevel();
                }
            }
        }
        setValue(BigInteger.valueOf(lvevl));
    }

    @Override
    public void addTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.TwinsKangfuComb.getValue(), handle);
    }

    @Override
    public void removeTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.TwinsKangfuComb.getValue(), handle);
    }

    public boolean isCompleted(GamePlayer player) {
        List<BigInteger> paramList = getActivityConditionInfo().getParamList();
        return getValue().compareTo(paramList.get(3)) >= 0;
    }
}
